namespace SmartSoft.SystemForms
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.Properties;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Data;  
    using System.IO;
    using System.Windows.Forms;
    using System.Diagnostics;

    public class FormLogIn : FormControl
    {
        private BtnControl btnAttachDB;
        private BtnControl btnCancel;
        private BtnControl btnCloseCode;
        private BtnControl btnCreateDB;
        private BtnControl btnOk;
        private BtnControl btnOkCode;
        private BtnControl btnServer;
        private BtnControl cmdBackup;
        private IContainer components;
        private GroupBox DatabaseInfo;
        private PictureBox SSBack;
        private GBoxControl gBoxControl1;
        private bool ib_CheckAccepted;
        private bool ib_CheckDetail;
        private LabelControl lblBackup;
        private LabelControl lblDBDatabase;
        private LabelControl lblDBPassword;
        private LabelControl lblDBServer;
        private LabelControl lblDBUserName;
        private LabelControl lblPassword;
        private LabelControl lblUserName;
        private PictureBox Line;
        private PictureBox Logo;
        private TextControl txtBackup;
        private TextControl txtDBDatabase;
        private TextControl txtDBPassword;
        private TextControl txtDBServer;
        private TextControl txtDBUserName;
        private TextControl txtPassword;
        private TextControl txtSerial1;
        private TextControl txtSerial2;
        private TextControl txtSerial3;
        private TextControl txtSerial4;
        private TextControl txtSerial5;
        private TextControl txtUserName;        

        public FormLogIn()
        {
            this.InitializeComponent();                     
            this.txtDBServer.DataBindings.Add("Text", SSSettings.Default, "ServerName", true, DataSourceUpdateMode.OnValidation);
            this.txtDBUserName.DataBindings.Add("Text", SSSettings.Default, "ServerUserName", true, DataSourceUpdateMode.OnValidation);
            this.txtDBPassword.DataBindings.Add("Text", SSSettings.Default, "ServerPassword", true, DataSourceUpdateMode.OnValidation);
            this.txtDBDatabase.DataBindings.Add("Text", SSSettings.Default, "DatabaseName", true, DataSourceUpdateMode.OnValidation);
            this.txtBackup.DataBindings.Add("Text", SSSettings.Default, "DatabaseBackupPath", true, DataSourceUpdateMode.OnValidation);
            this.txtUserName.Text = "";
            this.txtPassword.Text = "";

            //string str = AppInstance.SoftwareActiveCode.Substring(0, 4);
            //string str2 = AppInstance.SoftwareActiveCode.Substring(5, 4);
            //string str3 = AppInstance.SoftwareActiveCode.Substring(10, 4);
            //string str4 = AppInstance.SoftwareActiveCode.Substring(15, 4);
            //string str5 = AppInstance.SoftwareActiveCode.Substring(20, 4);
            //if (!AppInstance.SoftwareDecode(0x89, str, str2, str3, str4, str5) && !AppInstance.SoftwareDecode(0x8b, str, str2, str3, str4, str5))
            //{
            //    this.lblUserName.Visible = false;
            //    this.txtUserName.Visible = false;
            //    this.lblPassword.Visible = false;
            //    this.txtPassword.Visible = false;
            //    this.btnOk.Visible = false;
            //    this.btnCancel.Visible = false;
            //    this.btnServer.Visible = false;
            //    this.gBoxControl1.Visible = true;
            //    this.btnOkCode.Visible = true;
            //    this.btnCloseCode.Visible = true;
            //}

            AdapterInstance.IsRemoteConnected = global::SmartSoft.Properties.Settings.Default.RemoteConnectionMode;
            if (AdapterInstance.IsRemoteConnected)
            {
                btnServer.Enabled = false;                
            }            
        }

        private void AttachDatabase(string psMDFFile, string psLDFFile)
        {
            this.Refresh();
            string databaseName = AppInstance.DatabaseName;
            AppInstance.DatabaseName = "";
            AppInstance.GetConnectionString();
            if (!SSDataAccess.CheckConnected)
            {
                AppInstance.DatabaseName = databaseName;
                MessageBox.Show("Hãy kiểm tra Thông tin kết nối cơ sở dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                SSDataAccess.RunSQLCommand("sp_attach_db '" + databaseName + "', '" + psMDFFile + "', '" + psLDFFile + "'");
                AppInstance.DatabaseName = databaseName;
                AppInstance.GetConnectionString();
                SSDataAccess.CheckConnected = false;
                //SSDataAccess.SSConnection = null;
                MessageBox.Show("Đã thực hiện xong!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void btnAttachDB_Click(object sender, EventArgs e)
        {
            if (!AppInstance.CheckServer())
            {
                MessageBox.Show("Chức năng này chỉ thực hiện được tại máy chủ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                FormAttachDatabase database = new FormAttachDatabase();
                database.ShowDialog();
                if (database.CheckAccepted)
                {
                    this.AttachDatabase(database.MDFStringFile, database.LDFStringFile);
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {            
            base.Close();
        }

        private void btnCloseCode_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnCreateDB_Click(object sender, EventArgs e)
        {
            if (!AppInstance.CheckServer())
            {
                MessageBox.Show("Chức năng này chỉ thực hiện được tại máy chủ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                FormCreateDatabase database = new FormCreateDatabase();
                database.ShowDialog();
                if (database.CheckAccepted)
                {
                    this.CreateDatabase(database.StringLocation, database.InsertDEMOData);
                }
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            AppInstance.GetConnectionString();
            SSDataAccess.CheckConnected = true;
            if (SSDataAccess.CheckConnected)
            {
                AppInstance.UserName = this.txtUserName.Text;
                AppInstance.Password = this.txtPassword.Text;
                AppInstance.OnSave();
            }
            else
            {
                if (!this.ib_CheckDetail)
                {
                    this.ShowDBInfo();
                }
                MessageBox.Show("Hãy kiểm tra Thông tin kết nối cơ sở dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            UserDataAccess access = new UserDataAccess();
            //VBSPService.UserDataAccess access = new SmartSoft.VBSPService.UserDataAccess();            
            if (access.UserValidated(AppInstance.UserName, AppInstance.Password))
            {                
                AppInstance.FullName = access.GetUserName(AppInstance.UserName);
                AppInstance.UserType = access.GetUserType(AppInstance.UserName);
                AppInstance.UserValiated = true;
            }
            else
            {
                MessageBox.Show("Không kết nối được tới cơ sở dữ liệu (" + AppInstance.DatabaseName + ").\nVới người sử dụng '" + AppInstance.UserName + "'!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            AppInstance.InitSysMem();
            AppInstance.InitUserMem();
            if (!AppInstance.CompanyRegister(AppInstance.DefaultSubsidiary))
            {
                new FormCompanyList(true).ShowDialog();
            }
            AppInstance.CompanyRegister();
            this.CheckAccepted = true;
            base.Close();
        }

        private void btnOkCode_Click(object sender, EventArgs e)
        {
            string str = this.txtSerial1.Text.Trim();
            string str2 = this.txtSerial2.Text.Trim();
            string str3 = this.txtSerial3.Text.Trim();
            string str4 = this.txtSerial4.Text.Trim();
            string str5 = this.txtSerial5.Text.Trim();            

            if (!AppInstance.SoftwareDecode(0x89, str, str2, str3, str4, str5) && !AppInstance.SoftwareDecode(0x8b, str, str2, str3, str4, str5))
            {
                MessageBox.Show("Mã số k\x00edch hoạt chương trình không chính xác!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }

            //else
            //{
                this.lblUserName.Visible = true;
                this.txtUserName.Visible = true;
                this.lblPassword.Visible = true;
                this.txtPassword.Visible = true;
                this.btnOk.Visible = true;
                this.btnCancel.Visible = true;
                this.btnServer.Visible = true;
                this.txtUserName.Focus();
                this.gBoxControl1.Visible = false;
                this.btnOkCode.Visible = false;
                this.btnCloseCode.Visible = false;
                AppInstance.SoftwareActiveCode = str + "-" + str2 + "-" + str3 + "-" + str4 + "-" + str5;
                AppInstance.OnSave();
                MessageBox.Show("Chương trình đã được k\x00edch hoạt!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //}
        }

        private void btnServer_Click(object sender, EventArgs e)
        {
            this.ShowDBInfo();
        }

        private void cmdBackup_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.ShowNewFolderButton = true;
            dialog.ShowDialog();
            AppInstance.DatabaseBackupPath = dialog.SelectedPath;
        }

        private void CreateDatabase(string psDatabaseLocation, bool pbInsertDEMOData)
        {
            this.Refresh();
            this.Cursor = Cursors.WaitCursor;
            AppInstance.GetConnectionString();
            if (SSDataAccess.CheckConnected)
            {
                MessageBox.Show("Tên cơ sở dữ liệu '" + AppInstance.DatabaseName + "' đã tồn tại!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                string databaseName = AppInstance.DatabaseName;
                SSDataAccess.CheckConnected = false;
                //SSDataAccess.SSConnection = null;
                AppInstance.DatabaseName = "";
                AppInstance.GetConnectionString();
                if (!SSDataAccess.CheckConnected)
                {
                    AppInstance.DatabaseName = databaseName;
                    MessageBox.Show("Hãy kiểm tra Thông tin kết nối cơ sở dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    bool flag = SSDataAccess.RunSQLCommand("CREATE DATABASE " + databaseName + " ON (NAME = " + databaseName + ", FILENAME = '" + psDatabaseLocation + databaseName + ".mdf')");
                    AppInstance.DatabaseName = databaseName;
                    SSDataAccess.CheckConnected = false;
                    //SSDataAccess.SSConnection = null;
                    AppInstance.GetConnectionString();
                    if (flag)
                    {
                        while (!SSDataAccess.CheckConnected)
                        {
                        }
                    }
                    if ((!this.CreateTables() || !this.CreateSTPGs()) || !this.CreateSystemData())
                    {
                        MessageBox.Show("Hãy kiểm tra Thông tin kết nối cơ sở dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    else
                    {
                        if (pbInsertDEMOData)
                        {
                            this.CreateDEMOData();
                        }
                        this.Cursor = Cursors.Default;
                        MessageBox.Show("Đã thực hiện xong!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
            }
        }

        private bool CreateDEMOData()
        {
            if (!File.Exists(Application.StartupPath + @"\DEMODATA.sql"))
            {
                return false;
            }
            UserDataAccess access = new UserDataAccess();
            SSDataAccess.RunSQLCommand(access.Base64Decode(File.ReadAllText(Application.StartupPath + @"\DEMODATA.sql")));
            return true;
        }

        private bool CreateSTPGs()
        {
            if (!File.Exists(Application.StartupPath + @"\STPGFILE.sql"))
            {
                return false;
            }
            DataTable table = new DataTable("STPGsFile");
            DataColumn column = null;
            DataRow row = null;
            column = new DataColumn();
            column.ColumnName = "STPGData";
            column.DataType = System.Type.GetType("System.String");
            table.Columns.Add(column);
            column = new DataColumn();
            column.ColumnName = "Passed";
            column.DataType = System.Type.GetType("System.Boolean");
            table.Columns.Add(column);
            string str = new UserDataAccess().Base64Decode(File.ReadAllText(Application.StartupPath + @"\STPGFILE.sql"));
            string str2 = "\r\n";
            string str3 = "";
            while (str.Contains("begin procedure:->"))
            {
                str3 = str.Substring(0, str.IndexOf("end procedure"));
                str3.Substring(str3.IndexOf("begin procedure:->") + 0x12, str3.IndexOf(str2 + "begin contend:->") - 0x12);
                str3 = str3.Substring(str3.IndexOf("begin contend:->") + 0x10);
                str = str.Substring(str.IndexOf("end procedure") + 13);
                if (!SSDataAccess.RunSQLCommand(str3))
                {
                    row = table.NewRow();
                    row["STPGData"] = str3;
                    row["Passed"] = false;
                    table.Rows.Add(row);
                }
            }
            if (table.Rows.Count > 0)
            {
                bool flag = true;
                while (flag)
                {
                    flag = false;
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        row = table.Rows[i];
                        if (!((bool) row["Passed"]))
                        {
                            if (!SSDataAccess.RunSQLCommand(row["STPGData"].ToString()))
                            {
                                flag = true;
                            }
                            else
                            {
                                row["Passed"] = true;
                            }
                        }
                    }
                }
            }
            return true;
        }

        private bool CreateSystemData()
        {
            if (!File.Exists(Application.StartupPath + @"\SYSDATA.sql"))
            {
                return false;
            }
            UserDataAccess access = new UserDataAccess();
            string sql = access.Base64Decode(File.ReadAllText(Application.StartupPath + @"\SYSDATA.sql"));
            File.AppendAllText("SYSDATA.TXT", sql);
            SSDataAccess.RunSQLCommand(access.Base64Decode(File.ReadAllText(Application.StartupPath + @"\SYSDATA.sql")));
            return true;
        }

        private bool CreateTables()
        {
            if (!File.Exists(Application.StartupPath + @"\DATABASE.sql"))
            {
                return false;
            }            
            string str = new UserDataAccess().Base64Decode(File.ReadAllText(Application.StartupPath + @"\DATABASE.sql"));
            //File.Create("SQL.SQL");
            File.WriteAllText("SQL.SQL", str);
            //File.AppendAllText("SQL.SQL", str);
            string str2 = "\r\n";
            string str3 = "";
            while (str.Contains(str2 + "go" + str2))
            {
                str3 = str.Substring(0, str.IndexOf(str2 + "go" + str2));
                str = str.Substring(str.IndexOf(str2 + "go" + str2) + 6);
                SSDataAccess.RunSQLCommand(str3);
            }
            return true;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLogIn));
            this.Line = new System.Windows.Forms.PictureBox();
            this.Logo = new System.Windows.Forms.PictureBox();
            this.SSBack = new System.Windows.Forms.PictureBox();
            this.lblUserName = new SmartSoft.Controls.LabelControl();
            this.txtUserName = new SmartSoft.Controls.TextControl();
            this.lblPassword = new SmartSoft.Controls.LabelControl();
            this.txtPassword = new SmartSoft.Controls.TextControl();
            this.btnOk = new SmartSoft.Controls.BtnControl();
            this.btnCancel = new SmartSoft.Controls.BtnControl();
            this.btnServer = new SmartSoft.Controls.BtnControl();
            this.DatabaseInfo = new System.Windows.Forms.GroupBox();
            this.cmdBackup = new SmartSoft.Controls.BtnControl();
            this.txtBackup = new SmartSoft.Controls.TextControl();
            this.lblBackup = new SmartSoft.Controls.LabelControl();
            this.txtDBDatabase = new SmartSoft.Controls.TextControl();
            this.lblDBDatabase = new SmartSoft.Controls.LabelControl();
            this.txtDBPassword = new SmartSoft.Controls.TextControl();
            this.lblDBPassword = new SmartSoft.Controls.LabelControl();
            this.txtDBUserName = new SmartSoft.Controls.TextControl();
            this.lblDBUserName = new SmartSoft.Controls.LabelControl();
            this.txtDBServer = new SmartSoft.Controls.TextControl();
            this.lblDBServer = new SmartSoft.Controls.LabelControl();
            this.btnAttachDB = new SmartSoft.Controls.BtnControl();
            this.btnCreateDB = new SmartSoft.Controls.BtnControl();
            this.btnCloseCode = new SmartSoft.Controls.BtnControl();
            this.btnOkCode = new SmartSoft.Controls.BtnControl();
            this.gBoxControl1 = new SmartSoft.Controls.GBoxControl();
            this.txtSerial1 = new SmartSoft.Controls.TextControl();
            this.txtSerial5 = new SmartSoft.Controls.TextControl();
            this.txtSerial4 = new SmartSoft.Controls.TextControl();
            this.txtSerial2 = new SmartSoft.Controls.TextControl();
            this.txtSerial3 = new SmartSoft.Controls.TextControl();
            ((System.ComponentModel.ISupportInitialize)(this.Line)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.Logo)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.SSBack)).BeginInit();
            this.DatabaseInfo.SuspendLayout();
            this.gBoxControl1.SuspendLayout();
            this.SuspendLayout();
            // 
            // Line
            // 
            this.Line.BackColor = System.Drawing.Color.White;
            this.Line.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.Line.Image = global::SmartSoft.Properties.Resources.Line;
            this.Line.Location = new System.Drawing.Point(0, 99);
            this.Line.Name = "Line";
            this.Line.Size = new System.Drawing.Size(354, 5);
            this.Line.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.Line.TabIndex = 5;
            this.Line.TabStop = false;
            // 
            // Logo
            // 
            this.Logo.BackColor = System.Drawing.Color.White;
            this.Logo.BackgroundImage = global::SmartSoft.Properties.Resources.BANNER_LOGIN;
            this.Logo.Location = new System.Drawing.Point(0, 0);
            this.Logo.Name = "Logo";
            this.Logo.Size = new System.Drawing.Size(353, 99);
            this.Logo.TabIndex = 4;
            this.Logo.TabStop = false;
            // 
            // SSBack
            // 
            this.SSBack.BackColor = System.Drawing.Color.White;
            this.SSBack.Dock = System.Windows.Forms.DockStyle.Top;
            this.SSBack.Location = new System.Drawing.Point(0, 0);
            this.SSBack.Name = "SSBack";
            this.SSBack.Size = new System.Drawing.Size(353, 104);
            this.SSBack.TabIndex = 3;
            this.SSBack.TabStop = false;
            // 
            // lblUserName
            // 
            this.lblUserName.AutoSize = true;
            this.lblUserName.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblUserName.Location = new System.Drawing.Point(43, 117);
            this.lblUserName.Name = "lblUserName";
            this.lblUserName.Size = new System.Drawing.Size(79, 14);
            this.lblUserName.TabIndex = 0;
            this.lblUserName.Text = "Người sử dụng";
            // 
            // txtUserName
            // 
            this.txtUserName.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtUserName.CheckTextSearched = false;
            this.txtUserName.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtUserName.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtUserName.Location = new System.Drawing.Point(139, 114);
            this.txtUserName.MaxLength = 32;
            this.txtUserName.Name = "txtUserName";
            this.txtUserName.OldValue = null;
            this.txtUserName.Size = new System.Drawing.Size(171, 20);
            this.txtUserName.TabIndex = 0;
            this.txtUserName.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtUserName.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtUserName.Value = ((object)(resources.GetObject("txtUserName.Value")));
            // 
            // lblPassword
            // 
            this.lblPassword.AutoSize = true;
            this.lblPassword.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblPassword.Location = new System.Drawing.Point(43, 143);
            this.lblPassword.Name = "lblPassword";
            this.lblPassword.Size = new System.Drawing.Size(50, 14);
            this.lblPassword.TabIndex = 2;
            this.lblPassword.Text = "Mật khẩu";
            // 
            // txtPassword
            // 
            this.txtPassword.CheckTextSearched = false;
            this.txtPassword.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtPassword.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtPassword.Location = new System.Drawing.Point(139, 140);
            this.txtPassword.MaxLength = 128;
            this.txtPassword.Name = "txtPassword";
            this.txtPassword.OldValue = null;
            this.txtPassword.Size = new System.Drawing.Size(171, 20);
            this.txtPassword.TabIndex = 1;
            this.txtPassword.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemDescription;
            this.txtPassword.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.None;
            this.txtPassword.UseSystemPasswordChar = true;
            this.txtPassword.Value = ((object)(resources.GetObject("txtPassword.Value")));
            // 
            // btnOk
            // 
            this.btnOk.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnOk.Location = new System.Drawing.Point(50, 174);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(80, 23);
            this.btnOk.TabIndex = 2;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
            // 
            // btnCancel
            // 
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnCancel.Location = new System.Drawing.Point(136, 174);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(80, 23);
            this.btnCancel.TabIndex = 3;
            this.btnCancel.Text = "&Quay ra";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // btnServer
            // 
            this.btnServer.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnServer.Location = new System.Drawing.Point(222, 174);
            this.btnServer.Name = "btnServer";
            this.btnServer.Size = new System.Drawing.Size(80, 23);
            this.btnServer.TabIndex = 4;
            this.btnServer.Text = "&Hiển thị >>";
            this.btnServer.UseVisualStyleBackColor = true;
            this.btnServer.Click += new System.EventHandler(this.btnServer_Click);
            // 
            // DatabaseInfo
            // 
            this.DatabaseInfo.Controls.Add(this.cmdBackup);
            this.DatabaseInfo.Controls.Add(this.txtBackup);
            this.DatabaseInfo.Controls.Add(this.lblBackup);
            this.DatabaseInfo.Controls.Add(this.txtDBDatabase);
            this.DatabaseInfo.Controls.Add(this.lblDBDatabase);
            this.DatabaseInfo.Controls.Add(this.txtDBPassword);
            this.DatabaseInfo.Controls.Add(this.lblDBPassword);
            this.DatabaseInfo.Controls.Add(this.txtDBUserName);
            this.DatabaseInfo.Controls.Add(this.lblDBUserName);
            this.DatabaseInfo.Controls.Add(this.txtDBServer);
            this.DatabaseInfo.Controls.Add(this.lblDBServer);
            this.DatabaseInfo.Location = new System.Drawing.Point(19, 212);
            this.DatabaseInfo.Name = "DatabaseInfo";
            this.DatabaseInfo.Size = new System.Drawing.Size(314, 155);
            this.DatabaseInfo.TabIndex = 5;
            this.DatabaseInfo.TabStop = false;
            this.DatabaseInfo.Text = "Thông tin kết nối cơ sở dữ liệu";
            this.DatabaseInfo.Visible = false;
            // 
            // cmdBackup
            // 
            this.cmdBackup.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.cmdBackup.Font = new System.Drawing.Font("Arial", 8.25F);
            this.cmdBackup.Location = new System.Drawing.Point(278, 122);
            this.cmdBackup.Name = "cmdBackup";
            this.cmdBackup.Size = new System.Drawing.Size(30, 22);
            this.cmdBackup.TabIndex = 9;
            this.cmdBackup.Text = "...";
            this.cmdBackup.UseVisualStyleBackColor = true;
            this.cmdBackup.Click += new System.EventHandler(this.cmdBackup_Click);
            // 
            // txtBackup
            // 
            this.txtBackup.CheckTextSearched = false;
            this.txtBackup.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtBackup.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtBackup.Location = new System.Drawing.Point(55, 123);
            this.txtBackup.Name = "txtBackup";
            this.txtBackup.OldValue = null;
            this.txtBackup.Size = new System.Drawing.Size(219, 20);
            this.txtBackup.TabIndex = 7;
            this.txtBackup.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtBackup.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtBackup.Value = ((object)(resources.GetObject("txtBackup.Value")));
            // 
            // lblBackup
            // 
            this.lblBackup.AutoSize = true;
            this.lblBackup.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblBackup.Location = new System.Drawing.Point(6, 126);
            this.lblBackup.Name = "lblBackup";
            this.lblBackup.Size = new System.Drawing.Size(43, 14);
            this.lblBackup.TabIndex = 8;
            this.lblBackup.Text = "Backup";
            // 
            // txtDBDatabase
            // 
            this.txtDBDatabase.CheckTextSearched = false;
            this.txtDBDatabase.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtDBDatabase.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDBDatabase.Location = new System.Drawing.Point(120, 97);
            this.txtDBDatabase.Name = "txtDBDatabase";
            this.txtDBDatabase.OldValue = null;
            this.txtDBDatabase.Size = new System.Drawing.Size(171, 20);
            this.txtDBDatabase.TabIndex = 3;
            this.txtDBDatabase.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtDBDatabase.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtDBDatabase.Value = ((object)(resources.GetObject("txtDBDatabase.Value")));
            // 
            // lblDBDatabase
            // 
            this.lblDBDatabase.AutoSize = true;
            this.lblDBDatabase.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDBDatabase.Location = new System.Drawing.Point(24, 100);
            this.lblDBDatabase.Name = "lblDBDatabase";
            this.lblDBDatabase.Size = new System.Drawing.Size(92, 14);
            this.lblDBDatabase.TabIndex = 6;
            this.lblDBDatabase.Text = "Tên cơ sở dữ liệu";
            // 
            // txtDBPassword
            // 
            this.txtDBPassword.CheckTextSearched = false;
            this.txtDBPassword.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtDBPassword.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDBPassword.Location = new System.Drawing.Point(120, 71);
            this.txtDBPassword.Name = "txtDBPassword";
            this.txtDBPassword.OldValue = null;
            this.txtDBPassword.Size = new System.Drawing.Size(171, 20);
            this.txtDBPassword.TabIndex = 2;
            this.txtDBPassword.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtDBPassword.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtDBPassword.UseSystemPasswordChar = true;
            this.txtDBPassword.Value = ((object)(resources.GetObject("txtDBPassword.Value")));
            // 
            // lblDBPassword
            // 
            this.lblDBPassword.AutoSize = true;
            this.lblDBPassword.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDBPassword.Location = new System.Drawing.Point(24, 74);
            this.lblDBPassword.Name = "lblDBPassword";
            this.lblDBPassword.Size = new System.Drawing.Size(50, 14);
            this.lblDBPassword.TabIndex = 4;
            this.lblDBPassword.Text = "Mật khẩu";
            // 
            // txtDBUserName
            // 
            this.txtDBUserName.CheckTextSearched = false;
            this.txtDBUserName.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtDBUserName.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDBUserName.Location = new System.Drawing.Point(120, 45);
            this.txtDBUserName.Name = "txtDBUserName";
            this.txtDBUserName.OldValue = null;
            this.txtDBUserName.Size = new System.Drawing.Size(171, 20);
            this.txtDBUserName.TabIndex = 1;
            this.txtDBUserName.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtDBUserName.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtDBUserName.Value = ((object)(resources.GetObject("txtDBUserName.Value")));
            // 
            // lblDBUserName
            // 
            this.lblDBUserName.AutoSize = true;
            this.lblDBUserName.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDBUserName.Location = new System.Drawing.Point(24, 48);
            this.lblDBUserName.Name = "lblDBUserName";
            this.lblDBUserName.Size = new System.Drawing.Size(79, 14);
            this.lblDBUserName.TabIndex = 2;
            this.lblDBUserName.Text = "Người sử dụng";
            // 
            // txtDBServer
            // 
            this.txtDBServer.CheckTextSearched = false;
            this.txtDBServer.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtDBServer.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDBServer.Location = new System.Drawing.Point(120, 19);
            this.txtDBServer.Name = "txtDBServer";
            this.txtDBServer.OldValue = null;
            this.txtDBServer.Size = new System.Drawing.Size(171, 20);
            this.txtDBServer.TabIndex = 0;
            this.txtDBServer.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtDBServer.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtDBServer.Value = ((object)(resources.GetObject("txtDBServer.Value")));
            // 
            // lblDBServer
            // 
            this.lblDBServer.AutoSize = true;
            this.lblDBServer.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDBServer.Location = new System.Drawing.Point(24, 22);
            this.lblDBServer.Name = "lblDBServer";
            this.lblDBServer.Size = new System.Drawing.Size(48, 14);
            this.lblDBServer.TabIndex = 0;
            this.lblDBServer.Text = "Máy chủ";
            // 
            // btnAttachDB
            // 
            this.btnAttachDB.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnAttachDB.Location = new System.Drawing.Point(50, 378);
            this.btnAttachDB.Name = "btnAttachDB";
            this.btnAttachDB.Size = new System.Drawing.Size(120, 23);
            this.btnAttachDB.TabIndex = 6;
            this.btnAttachDB.TabStop = false;
            this.btnAttachDB.Text = "&Gắn dữ liệu";
            this.btnAttachDB.UseVisualStyleBackColor = true;
            this.btnAttachDB.Click += new System.EventHandler(this.btnAttachDB_Click);
            // 
            // btnCreateDB
            // 
            this.btnCreateDB.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnCreateDB.Location = new System.Drawing.Point(182, 378);
            this.btnCreateDB.Name = "btnCreateDB";
            this.btnCreateDB.Size = new System.Drawing.Size(120, 23);
            this.btnCreateDB.TabIndex = 7;
            this.btnCreateDB.TabStop = false;
            this.btnCreateDB.Text = "&Tạo mới dữ liệu";
            this.btnCreateDB.UseVisualStyleBackColor = true;
            this.btnCreateDB.Click += new System.EventHandler(this.btnCreateDB_Click);
            // 
            // btnCloseCode
            // 
            this.btnCloseCode.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnCloseCode.Location = new System.Drawing.Point(193, 174);
            this.btnCloseCode.Name = "btnCloseCode";
            this.btnCloseCode.Size = new System.Drawing.Size(100, 23);
            this.btnCloseCode.TabIndex = 10;
            this.btnCloseCode.Text = "&Quay ra";
            this.btnCloseCode.UseVisualStyleBackColor = true;
            this.btnCloseCode.Visible = false;
            this.btnCloseCode.Click += new System.EventHandler(this.btnCloseCode_Click);
            // 
            // btnOkCode
            // 
            this.btnOkCode.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnOkCode.Location = new System.Drawing.Point(60, 174);
            this.btnOkCode.Name = "btnOkCode";
            this.btnOkCode.Size = new System.Drawing.Size(100, 23);
            this.btnOkCode.TabIndex = 9;
            this.btnOkCode.Text = "&Chấp nhận";
            this.btnOkCode.UseVisualStyleBackColor = true;
            this.btnOkCode.Visible = false;
            this.btnOkCode.Click += new System.EventHandler(this.btnOkCode_Click);
            // 
            // gBoxControl1
            // 
            this.gBoxControl1.Controls.Add(this.txtSerial1);
            this.gBoxControl1.Controls.Add(this.txtSerial5);
            this.gBoxControl1.Controls.Add(this.txtSerial4);
            this.gBoxControl1.Controls.Add(this.txtSerial2);
            this.gBoxControl1.Controls.Add(this.txtSerial3);
            this.gBoxControl1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.gBoxControl1.Location = new System.Drawing.Point(20, 114);
            this.gBoxControl1.Name = "gBoxControl1";
            this.gBoxControl1.Size = new System.Drawing.Size(312, 51);
            this.gBoxControl1.TabIndex = 8;
            this.gBoxControl1.TabStop = false;
            this.gBoxControl1.Text = "Mã số kích hoạt - Active code";
            this.gBoxControl1.Visible = false;
            // 
            // txtSerial1
            // 
            this.txtSerial1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtSerial1.CheckTextSearched = false;
            this.txtSerial1.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtSerial1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSerial1.Location = new System.Drawing.Point(14, 20);
            this.txtSerial1.MaxLength = 4;
            this.txtSerial1.Name = "txtSerial1";
            this.txtSerial1.OldValue = null;
            this.txtSerial1.Size = new System.Drawing.Size(52, 20);
            this.txtSerial1.TabIndex = 0;
            this.txtSerial1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtSerial1.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtSerial1.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtSerial1.Value = ((object)(resources.GetObject("txtSerial1.Value")));
            // 
            // txtSerial5
            // 
            this.txtSerial5.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtSerial5.CheckTextSearched = false;
            this.txtSerial5.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtSerial5.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSerial5.Location = new System.Drawing.Point(246, 20);
            this.txtSerial5.MaxLength = 4;
            this.txtSerial5.Name = "txtSerial5";
            this.txtSerial5.OldValue = null;
            this.txtSerial5.Size = new System.Drawing.Size(52, 20);
            this.txtSerial5.TabIndex = 4;
            this.txtSerial5.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtSerial5.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtSerial5.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtSerial5.Value = ((object)(resources.GetObject("txtSerial5.Value")));
            // 
            // txtSerial4
            // 
            this.txtSerial4.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtSerial4.CheckTextSearched = false;
            this.txtSerial4.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtSerial4.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSerial4.Location = new System.Drawing.Point(188, 20);
            this.txtSerial4.MaxLength = 4;
            this.txtSerial4.Name = "txtSerial4";
            this.txtSerial4.OldValue = null;
            this.txtSerial4.Size = new System.Drawing.Size(52, 20);
            this.txtSerial4.TabIndex = 3;
            this.txtSerial4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtSerial4.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtSerial4.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtSerial4.Value = ((object)(resources.GetObject("txtSerial4.Value")));
            // 
            // txtSerial2
            // 
            this.txtSerial2.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtSerial2.CheckTextSearched = false;
            this.txtSerial2.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtSerial2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSerial2.Location = new System.Drawing.Point(72, 20);
            this.txtSerial2.MaxLength = 4;
            this.txtSerial2.Name = "txtSerial2";
            this.txtSerial2.OldValue = null;
            this.txtSerial2.Size = new System.Drawing.Size(52, 20);
            this.txtSerial2.TabIndex = 1;
            this.txtSerial2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtSerial2.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtSerial2.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtSerial2.Value = ((object)(resources.GetObject("txtSerial2.Value")));
            // 
            // txtSerial3
            // 
            this.txtSerial3.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtSerial3.CheckTextSearched = false;
            this.txtSerial3.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtSerial3.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSerial3.Location = new System.Drawing.Point(130, 20);
            this.txtSerial3.MaxLength = 4;
            this.txtSerial3.Name = "txtSerial3";
            this.txtSerial3.OldValue = null;
            this.txtSerial3.Size = new System.Drawing.Size(52, 20);
            this.txtSerial3.TabIndex = 2;
            this.txtSerial3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtSerial3.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtSerial3.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtSerial3.Value = ((object)(resources.GetObject("txtSerial3.Value")));
            // 
            // FormLogIn
            // 
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(353, 415);
            this.Controls.Add(this.btnCloseCode);
            this.Controls.Add(this.btnOkCode);
            this.Controls.Add(this.DatabaseInfo);
            this.Controls.Add(this.btnCreateDB);
            this.Controls.Add(this.btnAttachDB);
            this.Controls.Add(this.txtPassword);
            this.Controls.Add(this.lblPassword);
            this.Controls.Add(this.txtUserName);
            this.Controls.Add(this.lblUserName);
            this.Controls.Add(this.Line);
            this.Controls.Add(this.Logo);
            this.Controls.Add(this.SSBack);
            this.Controls.Add(this.btnOk);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnServer);
            this.Controls.Add(this.gBoxControl1);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormLogIn";
            this.Text = "Đăng nhập";
            this.Load += new System.EventHandler(this.FormLogIn_Load);
            ((System.ComponentModel.ISupportInitialize)(this.Line)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.Logo)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.SSBack)).EndInit();
            this.DatabaseInfo.ResumeLayout(false);
            this.DatabaseInfo.PerformLayout();
            this.gBoxControl1.ResumeLayout(false);
            this.gBoxControl1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void ShowDBInfo()
        {
            if (!this.ib_CheckDetail)
            {
                this.ib_CheckDetail = true;
                this.btnServer.Text = "<< &Hiển thị";
                this.DatabaseInfo.Visible = true;
                this.txtDBServer.Focus();
                base.Height = 442;
            }
            else
            {
                this.ib_CheckDetail = false;
                this.btnServer.Text = "&Hiển thị >>";
                this.DatabaseInfo.Visible = false;
                this.txtUserName.Focus();
                base.Height = 242;
            }
        }

        public bool CheckAccepted
        {
            get
            {
                return this.ib_CheckAccepted;
            }
            set
            {
                this.ib_CheckAccepted = value;
            }
        }

        private void FormLogIn_Load(object sender, EventArgs e)
        {
            base.Height = 242;
        }
    }
}

